<?php
namespace app\admin\controller;
use app\common\model\Admin;
use app\common\model\User as UserModel;
use think\Controller;
use think\Db;

class User extends Common
{
	
	public function index()
	{
		if(request()->isAjax()){

			$where = [];

			if(input('type')=='username'){
				$where['username']= ['like',"%".input('where')."%"];
			}

			if(input('type')=='phone'){
				$where['phone']= input('where');
			}

			if(input('type')=='email'){
				$where['email']= input('where');
			}

			if(!input('where')){
				$where = [];
			}

			$list = UserModel::where($where)->paginate(input('limit'));

			$responData = [
				'code'=>0,
				'count'=>$list->total(),
				'data'=>$list->items(),
				'msg'=>''
			];

			echo json_encode($responData);
			
		}else{
			return $this->fetch();
		}
	}

	public function userdel()
	{
		$uid = input('uid'); 

		$res = UserModel::destroy($uid);

		if($res){
			$this->success('成功');
		}else{
			$this->error('失败');
		}
	}

	public function status()
	{
		// $this->error('失败');
		$data = input('post.');

		$user = UserModel::get($data['uid']);

		if($data['status']=='true'){
			$user->status= 0;
		}else{
			$user->status= 1;
		}

		$res = $user->save();

		if($res){
			$this->success('成功');
		}else{
			$this->error('失败');
		}
	}

	public function edit($value='')
	{
		$uid = input('uid');

		var_dump($uid);
	}
}